home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 13 - 1997 (partial) / 13.01 Jan 97 / Oddone.PreemptiveThreads Folder / Logger.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-03  |  1.2 KB  |  65 lines  |  [TEXT/CWIE]

  1. #ifndef __MOREFILESEXTRAS__
  2. #include    <MoreFilesExtras.h>
  3. #endif
  4.  
  5. #ifndef __MOREFILES__
  6. #include    <MoreFiles.h>
  7. #endif
  8.  
  9. #ifndef __FSPCOMPAT__
  10. #include    <FSpCompat.h>
  11. #endif
  12.  
  13.  
  14. #include    "FabWmemman.h"
  15. #include    "Logger.h"
  16.  
  17.  
  18. IOParam *OpenLogFile(const FSSpec *spec, OSType creator, OSErr *retErr, Boolean exists)
  19. {
  20. IOParam    *thePB/* = nil*/;
  21. short    refNum = 0;
  22. OSErr    err = noErr;
  23.  
  24. if (thePB = ffcalloc(sizeof(ParamBlockRec))) {
  25.     if (exists == false)
  26.         err = FSpCreateCompat(spec, creator, 'TEXT', smCurrentScript);
  27.     
  28.     if (err == noErr) {
  29.         if ((err = FSpOpenAware(spec, dmWrDenyWr, &refNum)) == noErr) {
  30. //            thePB->ioCompletion = nil;
  31.             thePB->ioRefNum = refNum;
  32.             thePB->ioPosMode = fsFromLEOF | noCacheMask;
  33.             }
  34.         else {
  35.             (void) FSpDeleteCompat(spec);
  36.             SAFEDESTROY(ffree, IOParam    *, thePB, IOParam    *)
  37.             }
  38.         }
  39.     else {
  40.         SAFEDESTROY(ffree, IOParam    *, thePB, IOParam    *)
  41.         }
  42.     }
  43. else
  44.     err = appMemFullErr;
  45.  
  46. *retErr = err;
  47. return thePB;
  48. }
  49.  
  50. void WriteToLogFile(IOParam *thePB, void *buffer, UInt32 bufSize)
  51. {
  52. thePB->ioBuffer = buffer;
  53. thePB->ioReqCount = bufSize;
  54. thePB->ioPosOffset = 0;
  55. (void) PBWriteSync((ParmBlkPtr)thePB);
  56. }
  57.  
  58.  
  59. void CloseLogFile(IOParam *thePB)
  60. {
  61. (void) FSClose(thePB->ioRefNum);
  62. ffree(thePB);
  63. }
  64.  
  65.